package definite.Guide.Book.LayoutManager;

import java.awt.Color;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

public class YAxisAlignX {

	public static Container makeIT(String title, float alignment) {
		String labels[] = { "--", "----", "--------", "------------" };
		JPanel container = new JPanel();
		TitledBorder border =
			new TitledBorder(null, title, TitledBorder.TOP,
					TitledBorder.CENTER, new Font("San-Serif", Font.BOLD, 16),
					Color.RED);
		container.setBorder(border);
		BoxLayout boxLayout = new BoxLayout(container, BoxLayout.Y_AXIS);
		container.setLayout(boxLayout);

		for (int i = 0; i < labels.length; i++) {
			JButton button = new JButton(labels[i]);
			button.setAlignmentX(alignment);
			container.add(button);
		}
		return container;
	}

	public static void main(String[] args) {
		Runnable r = new Runnable() {

			@Override
			public void run() {
				JFrame.setDefaultLookAndFeelDecorated(true);
				JFrame frame = new JFrame("Layout Manager");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

				Container leftPanel = makeIT("Left", Container.LEFT_ALIGNMENT);
				Container centerPanel =
					makeIT("Center", Container.CENTER_ALIGNMENT);
				Container rightPanel =
					makeIT("Right", Container.RIGHT_ALIGNMENT);

				frame.setLayout(new FlowLayout());
				frame.add(leftPanel);
				frame.add(centerPanel);
				frame.add(rightPanel);

				frame.pack();
				frame.setResizable(false);
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		};

		EventQueue.invokeLater(r);
	}

}
